<?php

require_once 'conexao.php';

$motorista = @strtoupper(strtr($_POST['motorista'] ,"áéíóúâêôãõàèìòùç","ÁÉÍÓÚÂÊÔÃÕÀÈÌÒÙÇ"));
$placa = @strtoupper(strtr($_POST['placa'] ,"áéíóúâêôãõàèìòùç","ÁÉÍÓÚÂÊÔÃÕÀÈÌÒÙÇ"));
$destino = @strtoupper(strtr($_POST['destino'] ,"áéíóúâêôãõàèìòùç","ÁÉÍÓÚÂÊÔÃÕÀÈÌÒÙÇ"));
$cracha = @$_POST['cracha'];
$capacete = @$_POST['capacete'];
$operacao = @$_POST['select_operacao'];
$login = $_SESSION['login'];

if ($destino == '') {
    $query = "INSERT INTO prestador (motorista, placa, cracha, capacete, operacao, dt_entrada, hr_entrada, port_ent) VALUES ('" . $motorista . "', '" . $placa . "', " . $cracha . ", " . $capacete . ", '" . $operacao . "', NOW(), NOW(), '" . $login . "')";
    mysql_query($query);
    $query = "DELETE FROM fila WHERE placa = '" . $placa . "'";
    mysql_query($query);
}
else {
    $query = "UPDATE prestador SET dt_saida = NOW(), hr_saida = NOW(), destino = '" . $destino . "',port_saida='" . $login . "' WHERE placa = '" . $placa . "' AND dt_saida = '0000-00-00'";
    mysql_query($query);
}

  echo "<script type='text/javascript'>
  document.location.href='index.php?pagina=prestador'
  </script> ";
 
?>
